﻿//  --------------------------------
//  Copyright (c) 2010 Michael Schuler, Sascha Burger. All rights reserved.
//  This source code is made available under the terms of the Microsoft Public License (Ms-PL)
//  http://p2pmessaging.codeplex.com/license
//  ---------------------------------
using System;
using NUnit.Framework;
using p2pMessaging.BL.Model;
using p2pMessaging.Contracts;
using p2pMessaging.Interfaces;

namespace p2pMessaging.Tests
{
	[TestFixture]
	public class SerializingTest
	{
		private ISerializeService mySerializeService;
		
		[SetUp]
		public void SetUp()
		{
			mySerializeService = ServiceLocator.Get<ISerializeService>();
		}
		
		[Test]
		public void SerializeToXml()
		{
			string body = "text für body";
			string title = "titel für message";
			string contactName = "hans rudolf";
			string contactEmail = "hr@test.local";
			
			IMessage message = new Message();
			message.Data = body;
			message.PluginId = Guid.NewGuid();
			message.Sender = new Contact { EmailAddress = contactEmail, FirstName = contactName };
			message.Subject = title;

			byte[] result = mySerializeService.Serialize(message);

			IMessage msg = mySerializeService.Deserialize<IMessage>(result);

			Assert.AreEqual(body, msg.Data);
			Assert.AreEqual(title, msg.Subject);
			Assert.AreEqual(contactEmail, message.Sender.EmailAddress);
			Assert.AreEqual(contactName, msg.Sender.FirstName);
		}
	}
}
